const {testedModel} = require('../models/completedTestModel');
const {questionsModel} = require('../models/questionsModel');

async function addCompletedTest(req, res, next) {
    const data = req.body;
    console.log(data);
    // console.log(TypeId);
    const result = await testedModel.create(data);
    if(result){
        res.send({
            code:'200',
            message:'添加成功'
           })
    }else{
      res.send({
        code:'500',
        message:'添加失败'
      })
    }
  }

async function getAnalysis(req, res, next){
   const data = req.query;
   const result = await testedModel
    .find(data)
    .populate({
      path:'test_id',
     
    })
    const KnowledgePointId = result[0].test_id.KnowledgePointId;
    const anaylise = await questionsModel.find({KnowledgePointId});
console.log(result,anaylise);
    if(result){
      res.send({
        code:200,
        result,
        anaylise
      })
    }
  }

module.exports={
  addCompletedTest,
  getAnalysis
}